package com.xj.business.simulate.bean.model;

import com.xj.common.model.Device;
import com.xj.common.model.Driver;
import com.xj.common.model.Point;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@Slf4j
@Component
public class ModelContent {
    private ModelData modelData = new ModelData();

    public   Point getPointByDeviceIdAndPointId(Long deviceId, Long pointId){
        return this.modelData.getPidToPoints().get(deviceId).get(pointId);
    }


    public List<Point> getPointByTenantid(Long tenantId){
        List<Point> points = new ArrayList<>();
        for(Driver driver: this.modelData.getDrivers().get(tenantId)){
            for(Device device: this.modelData.getDevices().get(driver.getId())){
                points.addAll(this.modelData.getPoints().get(device.getId()));
            }
        }
        return points;
    }

    public Map<Long ,List<Point>> getPointMapByTenantid(Long tenantId){
        Map<Long,List<Point>> points = new HashMap<>();
        for(Driver driver: this.modelData.getDrivers().get(tenantId)){
            for(Device device: this.modelData.getDevices().get(driver.getId())){
                points.put(device.getId(), this.modelData.getPoints().get(device.getId()));
            }
        }
        return points;
    }


    public Map<Long ,List<Point>> getPointMapByDriverid(Long driverId){
        Map<Long,List<Point>> points = new HashMap<>();
        for(Device device: this.modelData.getDevices().get(driverId)){
            points.put(device.getId(), this.modelData.getPoints().get(device.getId()));
        }
        return points;
    }
}